<template>
  <div class="page">
    <div class="box b2">b2</div>
    <div class="box b1" :style="style">b1</div>
  </div>
  <button @click="add">添加</button>
</template>
<script>
import { mat4 } from '../../libs/glmatrix/gl-matrix-min.js'
import { gsap } from '../../libs/gsap-3.11.1.min.js'
export default {
  data() {
    return {
      style: {}
    }
  },
  methods: {
    add() {
      console.log(`helloworld`)

      // 定义相机参数
      const eye = [-10, 0, 0] // 相机位置 (z 朝向屏幕外)
      const center = [0, 0, 0] // 目标点
      const up = [0, 1, 0] // 上方向

      // 生成视图矩阵 (WebGL 右手坐标系)
      const viewMatrix = mat4.create()
      mat4.lookAt(viewMatrix, eye, center, up)

      const viewMatrix_i = mat4.create()
      mat4.invert(viewMatrix_i, viewMatrix)
      // 转换为 CSS matrix3d 字符串
      const matrixArray = Array.from(viewMatrix_i)
      const cssTransform = `matrix3d(${matrixArray.join(',')})`

      // 应用到元素
      this.style.transform = cssTransform
    }
  },
  mounted() {
    this.add()
  }
}
</script>
<style type="text/css" lang="scss">
.page {
  transform-style: preserve-3d;
  perspective: 1000px;
}
.box {
  width: 100px;
  height: 100px;
  position: absolute;
  left: 100px;
  right: 100px;
  border: 1px solid #000;
  background: #fff;
  box-sizing: border-box;
  &.b2 {
    top: 200px;
  }
  &.b1 {
    z-index: 1;
    background: grey;
  }
}
</style>
